/*
 Funtions.h
 MailDelivery
 
 Created by Dante Palacios on 26/08/09.
 Copyright 2009 Dante Palacios. All rights reserved.
 */

/*!
 @header Funtions.h
 @discussion This header contains utility functions for the framework. Some of these functions may disappear or change their names without prior notice. For more information, contact palacios.dante\@gmail.com.
 */

#import <Foundation/Foundation.h>
#import <CoreServices/CoreServices.h>
#import <Security/Security.h>


/*!
 @function KeychainGetPasswordForAccount
 @abstract Gets a password from Keychain.
 @param account
 NSDictionary containing hostName and userName.
 @result the password for the given account.
 */

extern NSString *KeychainGetPasswordForAccount(NSDictionary *account);

/*!
 @function KeychainSetPasswordForAccount
 @abstract Sets a password for a KeychainItem.
 @param account
 NSDictionary containing hostName, userName, port, and password.
 @param password
 the password.
 */

extern BOOL KeychainSetPasswordForAccount(NSString *password, NSDictionary *account);

/*!
 @function IsImageFile
 @abstract Used to decide <tt>Part</tt> <tt>contentDisposition</tt>.
 @param path
 full path or filename.
 */

extern BOOL IsImageFile(NSString *path);

/*!
 @function IsAudioFile
 @abstract Used to decide <tt>Part</tt> <tt>contentDisposition</tt>.
 @param path
 full path or filename.
 */

extern BOOL IsAudioFile(NSString *path);

/*!
 @function IsMovieFile
 @abstract Used to decide <tt>Part</tt> <tt>contentDisposition</tt>.
 @param path
 full path or filename.
 */

extern BOOL IsMovieFile(NSString *path);


/*!
 @function IsValidEmail
 @abstract Checks if an mail address is valid.
 @param emailAddress
 the email address.
 @result YES if email is valid.
 */

extern BOOL IsValidEmail(NSString *emailAddress);

/*!
 @function IsMobileMeHost
 @abstract .
 @param hostName
 the name of the server.
 */

extern BOOL IsMobileMeHost(NSString *hostName);

/*!
 @function GetCertificateRefForEmail
 @abstract Searchs a certificate for specified email. You must CFRelease() the resulting (SecCertificateRef)itemRef.
 @param email
 the email
 @param itemRef
 a pointer to the wanted certificate.
 */

OSStatus GetCertificateRefForEmail(NSString *email, SecKeychainItemRef *itemRef);

/*!
 @function MailDeliveryValidateConnectionWithURL
 @abstract .
 @param url
 NSURL referring to the connection.
 @param diagnosticDescription
 a pointer to the diagnostic description.
 */

CFNetDiagnosticStatus MailDeliveryValidateConnectionWithURL(NSURL *url, NSString **diagnosticDescription);

/*!
 @function MailDeliveryValidateInternetConnection
 @abstract see below.
 */

CFNetDiagnosticStatus MailDeliveryValidateInternetConnection(NSString **diagnosticDescription);

/*!
 @function HumanReadableFileSizeUsingFormat
 @abstract Used to get a representation of a file size.
 @param fileSize
 the size of the file.
 @param format
 the format of the resulting file size, default format is "#,###.##;0.00;(#,##0.00)".
 @result returns the file size in human-readable form. E.g. 144, 25 KB.
 */

NSString *HumanReadableFileSizeUsingFormat(NSNumber *fileSize, NSString *format);

/*!
 @function MIMETypeOfFile
 @abstract Used to get mime type of a file.
 @param filename
 can be either full path of just the filename, filename must contain path extension.
 */

NSString *MIMETypeOfFile(NSString *filename);

/*!
 @function MailDeliveryLog
 @abstract .
 @param format
 .
 */

void MailDeliveryLog(NSString *format, ...);

/*!
 @function MailContentsOfURL
 @abstract .
 @param URL
 .
 */

BOOL MailContentsOfURL(NSURL *URL, NSString **errorDescription);

/*!
 @function MailLinkToURL
 @abstract .
 @param URL
 .
 */

BOOL MailLinkToURL(NSURL *URL, NSString **errorDescription);

